package cn.nwpu.eckel.Dao;

import static cn.nwpu.eckel.utility.DBConnection.close;

import static cn.nwpu.eckel.utility.DBConnection.getConnection;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.nwpu.eckel.model.User;

public class UserDao {
	public static User getUserByAccount(String account){
		User user=new User();
		Connection con=getConnection();
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		String sql="select* from user_tb where account=?";
		try{
			pstmt=con.prepareStatement(sql);
			pstmt.setString(1,account);
			rs=pstmt.executeQuery();
			while(rs.next()){
				user.id=rs.getInt(1);
				user.setName(rs.getString(2));
				user.setAccount(rs.getString(3));
				user.setPassword(rs.getString(4));
				user.setAuthority(rs.getInt(5));
			}
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			close(pstmt);
			close(con);
		}
		return user;
	}

}
